package com.ias.agdis_r.view.flight;

import com.ias.agdis_r.R;
import com.ias.agdis_r.bean.fight.FlightQueryValue;
import com.ias.agdis_r.util.S;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FlightArriveTimeView extends LinearLayout {

	/** 计划到达时间 */
	private TextView STO;
	/** 实际到达/起飞时间 */
	private TextView ATO;
	/** 预起 */
	private TextView ETO;

	public void setFlightQueryValue(FlightQueryValue flightQueryValue) {
		this.setSTO(getTime(flightQueryValue.getSTO()));
		this.setATO(getTime(flightQueryValue.getATO()));
		this.setETO(getTime(flightQueryValue.getETO()));
	}

	/** 计划到达时间 */
	public void setSTO(String STO) {
		this.STO.setText(STO);
	}

	/** 实际到达/起飞时间 */
	public void setATO(String ATO) {
		this.ATO.setText(ATO);
	}

	/** 预起 */
	public void setETO(String ETO) {
		this.ETO.setText(ETO);
	}

	public FlightArriveTimeView(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.view_flight_arrive_time, this);
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		initView();
	}

	private void initView() {
		this.STO = (TextView) findViewById(R.id.flightinfo_STO);
		this.ATO = (TextView) findViewById(R.id.flightinfo_ATO);
		this.ETO = (TextView) findViewById(R.id.flightinfo_ETO);
	}


	private String getTime(String time) {
		if (S.isNotEmpty(time) && time.length() == 19) {
			return time.substring(5, time.length());
		}
		return time;
	}
}
